/*
 * FramedRect.cpp
 *
 *  Created on: Jul 6, 2009
 *      Author: kurt
 */

#include "FramedRect.h"
#include "DrawingCanvas.h"
#include "Types.h"
#include <sstream>
using namespace std;
using namespace objdraw;

FramedRect::~FramedRect() 
{
	
}
FramedRect::FramedRect() 
{
	start = Location(0,0);
	end = Location(0,0);
	color = Color(0,0,0);
	hidden = false;
	canvas = NULL;
}
FramedRect::FramedRect(const FramedRect & r)
{
	start = r.start;
	end = r.end;
	color = r.color;
	hidden = r.hidden;
	canvas = r.canvas;
	if(canvas != NULL)
		canvas->getCanvasContent().addDrawable(this);
}
FramedRect::FramedRect(float x, float y, float width, float height, DrawingCanvas * c)
{
	start = Location(x,y);
	end = Location(x+width, y+height);
	color = Color(0,0,0);
	hidden = false;
	canvas = c;
	if(canvas != NULL)
		canvas->getCanvasContent().addDrawable(this);
}
FramedRect::FramedRect(Location origin, float width, float height, DrawingCanvas * c)
{
	start = origin;
	end = Location(origin.x+width, origin.y+height);
	color = Color(0,0,0);
	hidden = false;
	canvas = c;
	if(canvas != NULL)
		canvas->getCanvasContent().addDrawable(this);
}
FramedRect::FramedRect(Location p0, Location p1, DrawingCanvas * c)
{
	start = p0;
	end = p1;
	color = Color(0,0,0);
	hidden = false;
	canvas = c;
	if(canvas != NULL)
		canvas->getCanvasContent().addDrawable(this);
}
void FramedRect::render()
{
	if(hidden) return;
	
	sceGuDisable(GU_TEXTURE_2D);
	sceGuDisable(GU_DEPTH_TEST);
	
	Vertex * points = (Vertex *)sceGuGetMemory(sizeof(Vertex) * 5);
	points[0].color = points[1].color = points[2].color = points[3].color = color.gu_c();
	points[0].z = points[1].z = points[2].z = points[3].z = 0.0f;
	
	points[0].x = start.x;
	points[0].y = start.y;
	
	points[1].x = end.x;
	points[1].y = start.y;
	
	points[2].x = end.x;
	points[2].y = end.y;
	
	points[3].x = start.x;
	points[3].y = end.y;
	
	points[4] = points[0];
	
	sceGuDrawArray(GU_LINE_STRIP, GU_COLOR_8888|GU_VERTEX_32BITF|GU_TRANSFORM_2D, 5, 0, points);
	
	sceGuEnable(GU_TEXTURE_2D);
	sceGuEnable(GU_DEPTH_TEST);
}
string FramedRect::toString()
{
	stringstream rstr("FramedRect: ");
	rstr << "start: " << start.toString() << 
	"end: " << end.toString() << 
	"color: " << color.toString() <<
	"hidden: " << hidden;
	return rstr.str();
}

